package com.oj.system.controller.question;
import com.oj.common.core.constants.HttpConstants;
import com.oj.common.core.controller.BaseController;
import com.oj.common.core.domain.R;
import com.oj.common.core.domain.TableDataInfo;
import com.oj.system.domain.question.dto.QuestionEditDTO;
import com.oj.system.domain.question.dto.QuestionQueryDTO;
import com.oj.system.domain.question.dto.QuestionSaveTO;
import com.oj.system.domain.question.vo.QuestionDetailVO;
import com.oj.system.domain.question.vo.QuestionVO;
import com.oj.system.service.question.IQuestionService;
import com.oj.system.service.question.impl.QuestionServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.view.RedirectView;

/**
 * @Description
 * @Author bin
 * @Date 2025/4/27
 */

@RestController
@RequestMapping("/question")
@Tag(name = "题库问题Api")
public class QuestionController extends BaseController {

    @Autowired
    private QuestionServiceImpl questionService;

    @GetMapping("/list")
    @Operation(summary = "问题列表", description = "根据查询条件筛选查询问题列表")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务器繁忙,请稍后重试")
    public TableDataInfo list( QuestionQueryDTO questionQueryDTO, @RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return questionService.list(questionQueryDTO,token);
    }

    @PostMapping("/add")
    @Operation(summary = "添加问题", description = "根据输入内容添加题目")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务器繁忙,请稍后重试")
    public R<Void> add(@RequestBody @Validated QuestionSaveTO questionDTO) {
        return toR(questionService.add(questionDTO));
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除问题", description = "根据Id删除问题")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务器繁忙,请稍后重试")
    public R<Void> delete(Long questionId) {
        return questionService.delete(questionId);
    }

    @PutMapping("/edit")
    @Operation(summary = "编辑问题", description = "根据Id编辑问题")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务器繁忙,请稍后重试")
    public R<Void> edit(@RequestBody QuestionEditDTO questionDTO) {
        return questionService.edit(questionDTO);
    }

    @GetMapping("/detail")
    @Operation(summary = "查询某个题目信息", description = "根据Id编辑问题")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务器繁忙,请稍后重试")
    public R<QuestionDetailVO> detail(Long questionId) {
        return questionService.detail(questionId);
    }


    @GetMapping("/redirect")
    public RedirectView redirectWithRedirectView() {

        return new RedirectView("http://localhost:9081/login?redirect_uri=https://www.baidu.com");
    }
}
